const wsPool = require('../../../service/ws/connection_pool');

module.exports = (app, basePath) => {
  app.ws(`${basePath}/:clientId`, (ws, req) => {
    const { clientId } = req.params;
    console.log(`WebSocket connected: ${req.path}, ${clientId}`);
    wsPool.add(clientId, ws);
    
    ws.on('message', (msg) => {
      console.log(`Chat message received: ${msg}`);
      ws.send(`Chat echo: ${msg}`);
    });
    
    ws.on('close', () => {
      console.log('Chat WebSocket closed');
    });

  });
};
